// ==UserScript==
// @name i-cable.com.videofix
// @description fix 'i-cable.com' bug with videos not playing on linux platform
// @version 1.0.3
// @build-time 2012-05-16 20:52:53
// @include *.i-cable.com/*
// @run-at document-start
// ==/UserScript==

/*
 http://www.gnu.org/licenses/gpl.html 
*/
/*
 * by siutin (osiutino.wordpress.com)
 *
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 */

if( location.search.indexOf("video_id=") == 1 || location.search.indexOf("news_id=") == 1 ||
	location.href.indexOf("/video") > 1 ||
 location.href.indexOf("http://cablenews.i-cable.com/webapps/suddenfeed.php") == 0){
	
	console.log("loading script ..");

	(function(window,console){
		var waitThen = window.waitThen = function(name,callback){
			if( typeof window[name] == 'undefined'){
				console.log("wait for "+ name);
				setTimeout("waitThen('"+name+"',"+callback+")",25);
			}else
				if(typeof callback == "function")
					callback(window[name]);	
		}

		
		try{
			waitThen("BrowserDetect",function(_BrowserDetect){

			 	for(var i in _BrowserDetect)
			 		BrowserDetect[i] = _BrowserDetect[i];
			 	BrowserDetect.OS = BrowserDetect.OS.replace("Linux","Windows");

				waitThen("get_timestamp",function(get_timestamp){
					waitThen("vb",function(vb){
						get_timestamp();
				  		waitThen("load_jw_player",function(load_jw_player){
				  			load_jw_player();
					 		var vc = jwplayer("video_container");
							vc.play();
				  		})
					});
				});		
			})
		}catch(ex){
			console.error(new Error(ex).message);
		}
	})(window,console);

	console.log("script was loaded.");

}
